SPA_RESOLVE_INIT = function(transition) {
    var html = '<div class="right-list-box addexam-box mt-20 magin-auto">\n' +
        '<div class="items">\n' +
        '<label>标题：</label>\n' +
        '<input type="text" class="examName t t1 rad-3 ml-10 f-14" maxlength="20">\n' +
        '</div>\n' +
        '<div class="items">\n' +
        '<label>班级ID：</label>\n' +
        '<input type="number" class="t t7 rad-3 ml-10 f-14" maxlength="20" id="courseId"/>\n' +
        '</div>\n' +
        '<div class="items">\n' +
        '<label>考试状态：</label>\n' +
        '<select class="examStatus rad-3 t t3 ml-10 f-14">\n' +
        '<option value="">--请选择--</option>\n' +
        '<option value="1">True</option>\n' +
        '<option value="0">False</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '<div class="items">\n' +
        '<label>解锁密码：</label>\n' +
        '<input type="text" class="unlockSecret t t3 rad-3 ml-10 f-14" maxlength="20">\n' +
        '</div>\n' +
        '<div class="items">\n' +
        '<label>开始时间：</label>\n' +
        '<input type="date" class="t t7 rad-3 ml-10 f-14" id="startDate" placeholder="格式：2019-10-10"/>\n' +
        '<input type="time" class="t t7 rad-3 ml-10 f-14" id="startTime" placeholder="格式：18:00"/>\n' +
        '</div>\n' +
        '<div class="items">\n' +
        '<label>结束时间：</label>\n' +
        '<input type="date" class="t t7 rad-3 ml-10 f-14" id="endDate" placeholder="格式：2019-10-10"/>\n' +
        '<input type="time" class="t t7 rad-3 ml-10 f-14" id="endTime" placeholder="格式：18:00"/>\n' +
        '</div>\n' +
        '<!--自动组卷开始区-->\n' +
        '<div class="items hide">\n' +
        '<label>类型：</label>\n' +
        '<select class="rad-3 t t3 ml-10 f-14">\n' +
        '<option value="">--请选择--</option>\n' +
        '<option value="1">填空题</option>\n' +
        '<option value="2">选择题</option>\n' +
        '<option value="3">判断题</option>\n' +
        '<option value="4">程序填空题</option>\n' +
        '<option value="5">程序改错题</option>\n' +
        '<option value="6">编程题</option>\n' +
        '</select>\n' +
        '<label>难度：</label>\n' +
        '<select class="rad-3 t t3 ml-10 f-14">\n' +
        '<option>--请选择--</option>\n' +
        ' <option value="1">1</option>\n' +
        '          <option value="2">2</option>\n' +
        '          <option value="3">3</option>\n' +
        '          <option value="4">4</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '<div class="items hide">\n' +
        '<label>分值：</label>\n' +
        '<input type="text" class="t t3 rad-3 ml-10 f-14" maxlength="3">\n' +
        '<label>题数：</label>\n' +
        '<input type="text" class="t t3 rad-3 ml-10 f-14" maxlength="3">\n' +
        '<a href="javascript:;" class="btn-t c-fff f-14 bg-169 rad-3 ml-10 text-center">增加</a>\n' +
        '</div>\n' +
        '<!--自动组卷结束区-->\n' +
        '<div id="questions" class="questions">' +
        '<div class="items questionCont">\n' +
        '<div class="st">\n' +
        '<label>增加题号：</label>\n' +
        '<input type="number" class="question t t3 rad-3 ml-10 f-14"/>\n' +
        '<label>分值：</label>\n' +
        '<input type="number" class="score t t3 rad-3 ml-10 f-14"/>\n' +
        '</div>\n' +
        '<label></label>' +
        '<a href="javascript:;" class="add_question btn-t c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="add_question()">增加</a>\n' +
        '</div>\n' +
        '</div>' +
        '<div class="items mt-35">\n' +
        '<label></label>\n' +
        '<a href="javascript:;" class="btn-t c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="addPaperFun()">提交</a>\n' +
        '</div>\n' +
        '</div> ';
    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(4).show();
    document.getElementById("ui-right-content").innerHTML = html;
}

function addPaperFun(){
    var examName = $(".examName").val();
    var unlockSecret = $(".unlockSecret").val();
    var examStatus =$(".examStatus").val();
    var courseId = parseInt($("#courseId").val());
    var startTime = $("#startDate").val()+' '+$("#startTime").val();
    var endTime = $("#endDate").val()+' '+$("#endTime").val();
    var examQuestion=[]
    //预判断
    if(examName==""){
        $.message("请输入考试标题");
        return;
    }
    if(unlockSecret==""){
        $.message("请输入解锁密码");
        return;
    }
    if(examStatus==""){
        $.message("请输入考试状态");
        return;
    }
    if(courseId==""){
        $.message("请填写班级ID");
        return;
    }
    if($("#startDate").val()=="" || $("#startTime").val()==""){
        $.message("请填写开始时间");
        return;
    }
    if($("#endDate").val()=="" || $("#endTime").val()==""){
        $.message("请填写结束时间");
        return;
    }
    for(var i=0;i<$(".st").length;i++){
        question=$(".st").eq(i).find(".question").val();
        score=$(".st").eq(i).find(".score").val();
        if(question==""||score==""){
            $.message("请将题号和分值填写完整");
            return;
        }
        examQuestion.push({
            "question":parseInt(question),
            "score":parseInt(score)
        })
    }
    if(examQuestion.length==0){
        $.message("未添加题目");
        return;
    }
    $.ajax({
        url: add_paper_interface,
        type:'post',
        dataType:'json',
        contentType:"application/json",
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:JSON.stringify({
            paperQuestion:examQuestion
        }),
        success: function(data) {
            if(data.code==200){
                // $.message("添加成功");
                addExamFun(data.data.paperID)
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function addExamFun(paperId=5){
    var examName = $(".examName").val();
    var unlockSecret = $(".unlockSecret").val();
    var examStatus =$(".examStatus").val();
    var courseId = parseInt($("#courseId").val());
    var startTime = $("#startDate").val()+' '+$("#startTime").val();
    var endTime = $("#endDate").val()+' '+$("#endTime").val();
    examStatus=parseInt(examStatus)
    $.ajax({
        url: add_exam_interface,
        type:'post',
        dataType:'json',
        contentType:"application/json",
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:JSON.stringify({
            examName: examName,
            paperId: paperId,
            startTime: startTime,
            endTime: endTime,
            unlockSecret: unlockSecret,
            examStatus: examStatus,
            relateCourse: courseId
        }),
        success: function(data) {
            if(data.code==200){
                $.message("添加成功");
                setTimeout("location.href='#/examList'",500);
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function deleteQuestionCont(obj) {
    $(obj).closest('.questionCont').remove()
    $(".add_question").eq(-1).show()
}

function add_question() {
    $(".add_question").hide()
    var questionhtml='<div class="items questionCont">\n' +
        '<div class="st">\n' +
        '<label>题号：</label>\n' +
        '<input type="number" class="question t t3 rad-3 ml-10 f-14"/>\n' +
        '<label>分值：</label>\n' +
        '<input type="number" class="score t t3 rad-3 ml-10 f-14"/>\n' +
        '</div>\n' +
        '<label><a class="pull-left pl-15" onclick="deleteQuestionCont(this)">删除</a></label>'+
        '<a href="javascript:;" class="add_question btn-t c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="add_question()">增加</a>\n' +
        '</div>\n'
    $("#questions").append(questionhtml)
}